/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Data.config;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


/**
 *
 * @author César
 */
public class SessionFac {
    
    static SqlSessionFactory SessionFacB=null;
    
    private SessionFac(){}
    private SessionFac(SqlSessionFactory sessionFac){
		this.SessionFacB=sessionFac;
	}
    
    //private static String CONFIGURATION_FILE ="Data\\config\\mybatis-config.xml";
    //private static SqlSessionFactory sessionFac = null;
    //private static Reader reader;
    public static SqlSessionFactory SessionFactory(){
        if (SessionFacB!=null) return SessionFacB;
		try{
			SqlSessionFactory sqlSesionB;
			String resource = "Data/config/mybatis-config.xml";
			InputStream inputStream = Resources.getResourceAsStream(resource);
			SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
			sqlSesionB = builder.build(inputStream);
			return sqlSesionB;
			}
			catch(Exception e){
				System.out.println("error en conf");
				e.printStackTrace();
				
			}
		return SessionFacB;	
    }
}
